package com.ruoyi.server.api.share.controller;

import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.server.api.share.domain.Share;
import com.ruoyi.server.api.share.service.IShareService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 分享上传Controller
 *
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/share/share")
public class ShareController extends BaseController
{
    @Autowired
    private IShareService shareService;

    /**
    * @Author zsc
    * @Description 新增分享
    * @Date 2024/12/4 13:49
    * @Return com.ruoyi.common.core.domain.AjaxResult
    * @param share
    */
    @PostMapping("/insertShare")
    public AjaxResult insertShare(@RequestBody Share share)
    {
        return toAjax(shareService.insertShare(share));
    }


    /**
    * @Author zsc
    * @Description 根据id删除
    * @Date 2024/12/3 15:55
    * @Return com.ruoyi.common.core.domain.AjaxResult
    * @param id
    */
    @DeleteMapping("/deleteById")
    public AjaxResult deleteById(@RequestParam Long id)
    {
        return toAjax(shareService.deleteShareById(id));
    }

    /**
    * @Author zsc
    * @Description 查询所有分享
    * @Date 2024/11/14 9:08
    * @Return java.util.List<com.ruoyi.server.api.share.domain.Share>

    */
    @GetMapping("/lists")
    public AjaxResult lists()
    {
        List<Share> list = shareService.selectShareLists();
        return AjaxResult.success(list);
    }
    /**
    * @Author zsc
    * @Description 查询单用户分享
    * @Date 2024/11/14 9:18
    * @Return java.util.List<com.ruoyi.server.api.share.domain.Share>
    * @param userId
    */
    @GetMapping("/selectListById")
    public AjaxResult selectListById( BigInteger userId)
    {
        List<Share> list = shareService.selectListById(userId);
        return AjaxResult.success(list);
    }
    /**
     * 查询分享上传列表
     */
    @PreAuthorize("@ss.hasPermi('share:share:list')")
    @GetMapping("/list")
    public TableDataInfo list(Share share)
    {
        startPage();
        List<Share> list = shareService.selectShareList(share);
        return getDataTable(list);
    }

    /**
     * 导出分享上传列表
     */
    @PreAuthorize("@ss.hasPermi('share:share:export')")
    @Log(title = "分享上传", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Share share)
    {
        List<Share> list = shareService.selectShareList(share);
        ExcelUtil<Share> util = new ExcelUtil<Share>(Share.class);
        util.exportExcel(response, list, "分享上传数据");
    }

    /**
     * 获取分享上传详细信息
     */
    @PreAuthorize("@ss.hasPermi('share:share:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shareService.selectShareById(id));
    }

    /**
     * 新增分享上传
     */
    @PreAuthorize("@ss.hasPermi('share:share:add')")
    @Log(title = "分享上传", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Share share)
    {
        return toAjax(shareService.insertShare(share));
    }

    /**
     * 修改分享上传
     */
    @PreAuthorize("@ss.hasPermi('share:share:edit')")
    @Log(title = "分享上传", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Share share)
    {
        return toAjax(shareService.updateShare(share));
    }

    /**
     * 删除分享上传
     */
    @PreAuthorize("@ss.hasPermi('share:share:remove')")
    @Log(title = "分享上传", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shareService.deleteShareByIds(ids));
    }
}